package interview;

import java.util.Stack;

public class interview_03_02 {
    class MinStack {

        private Stack<int[]> minstack;
        private Stack<int[]> stack;
        int size;
        /** initialize your data structure here. */
        public MinStack() {
            minstack=new Stack<>();
            stack=new Stack<>();
            size=0;
        }

        public void push(int x) {
            stack.push(new int[]{x,size});
            if(!minstack.isEmpty()&&minstack.peek()[0]>x){
                minstack.push(new int[]{x,size});
            }
            if(minstack.isEmpty()) minstack.push(new int[]{x,size});
            size++;
        }

        public void pop() {
            int x=stack.pop()[1];
            if(minstack.peek()[1]==x) minstack.pop();
            size--;
        }

        public int top() {
            return stack.peek()[0];
        }

        public int getMin() {
            return minstack.peek()[0];
        }
    }
}
